<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 200px;
        }
    </style>
</head>

<body>
    <input type="button" value="红色" id="btn1">
    <input type="button" value="绿色" id="btn2">
    <input type="button" value="红色/绿色" id="btn3">
    <div class="box"></div>
    <script>
        var btn1 = document.querySelector("#btn1")
        var btn2 = document.querySelector("#btn2")
        var btn3 = document.querySelector("#btn3")
        var box = document.querySelector(".box")
        console.log(box);

        // 绑定点击事件
        btn1.onclick = function () {
            box.style.backgroundColor = "red"
        }
        btn2.onclick = function () {
            box.style.backgroundColor = "green"
        }
        btn3.onclick = function () {
            // 获取原本的背景颜色
            var color = window.getComputedStyle(box).backgroundColor;
            console.log(color);
            box.style.backgroundColor = color === "rgb(255,0,0)" ? "green" : "red"
        }
    </script>
</body>

</html>